﻿using System.Collections.Generic;
using UnityEngine;
using WssUtils;

namespace JQMergeFramework
{
    
    public class GameCfg
    {
        //随机事件每日次数限制
        public const int DayLimitEvent = 2;
        
        //房子下落动画时长
        public const float DownTime = 0.3F;

        //每五层盖一次房子
        public const int BuildTheHouse = 5;
        
        //合成所需最低数量
        public const int LimitMargeNum = 3;
        
        //ui动画时常
        public const float UIDTTime = 0.3F;

        //消除道具选择数量限制
        public const int RemoveCityLimitNum = 1;

        //直升机清除效果
        public const int HelicopterRemoveCityNum = 3;
        
        //随机事件出现条件300秒
        #if UNITY_GAME_TEST
            public const float EventShowTime = 180;
        #else
            public const float EventShowTime = 360;
        #endif
    

        
        //UI弹窗层name
        public const string UIPopName = "PopRoot";

        //每日使用道具次数限制
        public const int LimitDayUsePropNum = 5;
    }
    
    public enum EventTypes
    {
        Node,
        //直升机
        Helicopter,
        //无人机
        UAV,
    }

    public class  PropId
    {
        public const int RefreshProp = 0;
        
        public const int RemoveProp = 1;
        
        public const int DiscardProp = 2;
        
        public const int MoveProp = 3;
    }

    //随机方块配置
    public class CityData
    {
        //概率
        public int randomIdx;
        
        public int level;

        //方块形状、解锁旋转方向、概率值
        public CityData(int _randomIdx, int _level)
        {
            randomIdx = _randomIdx;
            level = _level;
        }
    }

    
    //关卡配置
    public class LevelCfg
    {
        public int id;
        public int targetLv;
        public int style;//房子的风格
    }

    //房子成就配置
    public class CityTargetCfg
    {
        public int lv;
        public string name;
        public string describe;//成就描述
        public string imgName;//图片名字
    }

    
    //数值
    public class NumericalCfg
    {
        public int id;
        public float curve;//曲线
        public float expectPlace;//预期放置次数
        public float averageCityLv;//平均建筑等级
        public int maxLv;//最高建筑等级
        public int addCityNum;//增加层数
        public int targetScore;//目标分数
        public int addScore;//累计分数

        public NumericalCfg(int _id,float _curve,float _expectPlace,float _averageCityLv,int _maxLv,int _addCityNum,int _targetScore, int _addScore)
        {
            id = _id; curve = _curve;
            expectPlace = _expectPlace;
            averageCityLv = _averageCityLv;
            maxLv = _maxLv;
            addCityNum = _addCityNum;
            targetScore = _targetScore;
            addScore = _addScore;
        }
    }

    //数值
    public class TempNumericalCfg
    {
        public int id;
        public float curve;//曲线
        public float expectPlace;//预期放置次数
        public float averageCityLv;//平均建筑等级
        public int maxLv;//最高建筑等级
        public int addCityNum;//增加层数
        public float targetScore;//目标分数
        public float addScore;//累计分数
    }
    
    
    //弹幕
    public class MarqueeCfg
    {
        public int id;
        public string descriptions;
    }

    public class CityConfig
    {
        //根据关卡等级获取格子
        public static List<CityData> GetCityIdList()
        {
            return new List<CityData>()
            {
                new CityData(200, 0),
                new CityData(100, 1),
                new CityData(50, 2),
                new CityData(25, 3),
                // new CityData(15, 4),
            };
        }

        
        
        //根据关卡等级获取格子
        public static int GetCityRandomId()
        {
            MyRandom.ResetSeed();
            
            //等级0级开始。-1
            int maxCityLv = MergeManager.Instance.NumericalCfg.maxLv;
            //等级-3
            int minCityLv = MergeManager.Instance.NumericalCfg.maxLv-3;
            minCityLv = minCityLv < 0 ? 0 : minCityLv;
            float averageCityLv = MergeManager.Instance.NumericalCfg.averageCityLv;
            float t = MyRandom.Range(averageCityLv, maxCityLv);
            float y = (t - averageCityLv) / (maxCityLv - averageCityLv);
            int id = (int)Mathf.Round(minCityLv + ((maxCityLv - minCityLv) * y));
            
            return id;
        }


        public static CityData RandomCityLv()
        {
            CityData d = new CityData(0,GetCityRandomId());
            return d;
        }



        //获取配置
        public static CityData RandomBlockCfg()
        {
            List<CityData> cityAryCfg = GetCityIdList();
            int total = 0;
            for (int i = 0; i < cityAryCfg.Count; i++)
            {
                total += cityAryCfg[i].randomIdx;
            }
            
            float rdTemp = MyRandom.Range(1, total);

            for (int i = 0; i < cityAryCfg.Count; i++)
            {
                if (rdTemp < cityAryCfg[i].randomIdx)
                {
                    return cityAryCfg[i];
                }
                else
                {
                    rdTemp -= cityAryCfg[i].randomIdx;
                }
            }
            
            return cityAryCfg[cityAryCfg.Count - 1];
        }
    }
    
    
    
}